<?php

declare(strict_types=1);

namespace App\Resource\Activity\Labour\Task;

use App\Enums\ActivityEnum;
use App\Models\MainDB\Gift;
use Illuminate\Http\Resources\Json\JsonResource;

class Resource extends JsonResource
{
    public function toArray($request)
    {
        if ($this->reward_type === Gift::RELATION_TYPE) {
            $this->reward = $this->gift;
        } else {
            $this->reward = $this->product;
        }
        $name = $this->reward->name ?? ($this->reward->title ?? '');
        return [
            'id'             => $this->id ?? null,
            'day'            => $this->day ?? null,
            'receive_status' => $this->receive_status ?? ActivityEnum::RECEIVE_STATUS_NO,
            'reward_id'      => $this->reward->id ?? null,
            'name'           => $name,
            'image'          => $this->reward->picture ?? null,
            'type'           => $this->reward_type ?? null,
            'count'          => $this->count ?? null,
        ];
    }
}
